<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>表格备注管理</title>
  <script src="./js/jexcel.js"></script>
  <script src="./js/jsuites.js"></script>
  <link rel="stylesheet" href="./css/jsuites.css" type="text/css" />
  <link rel="stylesheet" href="./css/jexcel.css" type="text/css" />
</head>

<body>
  <h1>表格备注管理</h1>

  <h3>1、允许用户为每个单元格设置自定义注释。通过在初始化中allowComments，用户将能够在右键单击contextMenu中添加注释。</h3>
  <div id="spreadsheet"></div>

  <button type="button" id="btn1" style="width:220px;">设置A1备注</button>
  <button type="button" id="btn2" style="width:220px;">获取A1备注</button>
  <button type="button" id="btn3" style="width:220px;">重置A1备注</button>
</body>

<script type="module">
  import { text } from "./js/language.js";

  let oBtn1 = document.getElementById('btn1');
  let oBtn2 = document.getElementById('btn2');
  let oBtn3 = document.getElementById('btn3');

  var data1 = [
    ['US', 'Cheese', '2019-02-12'],
    ['CA', 'Apples', '2019-03-01'],
    ['CA', 'Carrots', '2018-11-10'],
    ['BR', 'Oranges', '2019-01-12'],
  ];

  let mySpreadsheet = jspreadsheet(document.getElementById('spreadsheet'), {
    data: data1,
    columns: [
      {
        type: 'dropdown',
        url: './static/countries.json',
        width: 200,
      },
      {
        type: 'text',
        width: 200,
      },
      {
        type: 'calendar',
        width: 200,
      },
      {
        type: 'text',
        width: 200,
      }
    ],
    allowComments: true,
    text,
  });

  console.log('contextMenu', mySpreadsheet);

  oBtn1.onclick = function () {
    mySpreadsheet.setComments('A1', '我是A1单元格的备注信息');
  }

  oBtn2.onclick = function () {
    alert(mySpreadsheet.getComments('A1'));
  }

  oBtn3.onclick = function () {
    mySpreadsheet.setComments('A1', '');
  }
</script>

</html>